
#include "stdafx.h"
#include "schedule.h"


ScheduleItem::ScheduleItem()
{

}

ScheduleItem::ScheduleItem( ScheduleItem const& other )
{
	ATLASSERT( !other.m_strId.IsEmpty() );
	m_strId = other.m_strId;

	m_a1 = other.m_a1;
	m_a2 = other.m_a2;

	m_type = other.m_type;
	m_desc = other.m_desc;
	m_time = other.m_time;

	m_created = other.m_created;
}

ScheduleItem::~ScheduleItem()
{

}

void ScheduleItem::SetScheduleTime( A1 a1, A2 a2, SYSTEMTIME const& time )
{
	m_a1 = a1;
	m_a2 = a2;
	m_time = time;
}

void ScheduleItem::SetScheduleDesc( CString const& desc )
{
	m_desc = desc;
}

void ScheduleItem::SetScheduleType()
{

}

void ScheduleItem::GetScheduleTime( A1& a1, A2& a2, SYSTEMTIME& time ) const
{

}

// Is valid, it true means the item would be no used forever.
BOOL ScheduleItem::IsValid()
{
	
	return TRUE;
}

// If is expired today, the item may be useful tomorrow.
// If bToday = FALSE, the function ==> IsValid()
BOOL ScheduleItem::IsExpired( BOOL bToday /*= TRUE */ )
{
	if (bToday)
	{

		return TRUE;
	}
	else
	{
		return IsValid();
	}
}
//////////////////////////////////////////////////////////////////////////
void Schedule::AddScheduleItem( ScheduleItem const& item )
{
	m_schedule.push_back( item );
}


BOOL Schedule::IsScheduleDay( ScheduleItem const& scheduleItem, CTime const& day )
{
	ScheduleItem::A1 a1;
	ScheduleItem::A2 a2;
	SYSTEMTIME time;
	scheduleItem.GetScheduleTime( a1, a2, time );

	if (ScheduleItem::Every == a1)
	{
		switch (a2)
		{
		case ScheduleItem::Year:
			return (day.GetMonth() == time.wMonth && day.GetDay() == time.wDay);
			break;
		case ScheduleItem::Month:
			return (day.GetDay() == time.wDay);
			break;
		case ScheduleItem::Week:
			return day.GetDayOfWeek() == time.wDayOfWeek;
			break;
		case ScheduleItem::Day:
		case ScheduleItem::Hour:
		case ScheduleItem::Minute:
			return TRUE;
		default:
			return FALSE;
			break;
		}
	}
	else if (ScheduleItem::Some == a1)
	{
		switch (a2)
		{
		case ScheduleItem::Year:
		case ScheduleItem::Month:
		case ScheduleItem::Week:
		case ScheduleItem::Day:
		case ScheduleItem::Hour:
		case ScheduleItem::Minute:
		default:
			break;
		}
	}


	return FALSE;
}